package com.apes.fico.masterdata.gl.respository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.fico.masterdata.gl.model.AccountingPeriodItem;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

public interface AccountingPeriodItemRepository extends CustomRepository<AccountingPeriodItem, String> {
    @Query("select T from AccountingPeriodItem T where T.fromDate<=:value and T.thruDate>=:value and T.accountingPeriod.company.id=:company  ")
    AccountingPeriodItem findByPostDateAndCompany(@Param("value") Date Post, @Param("company") String company);

    @Query("select T from AccountingPeriodItem T where T.period_name=:period and T.accountingPeriod.company.id=:company")
    AccountingPeriodItem findByPeriodAndCompany(@Param("period") String period, @Param("company") String company);

    @Query("select T from AccountingPeriodItem T where T.month=:month and T.accountingPeriod.company.id=:company and T.accountingPeriod.year=:year")
    AccountingPeriodItem findByCompanyAndMonthAndYear(@Param("company") String company, @Param("month") int month, @Param("year") int year);

    @Query("select T from AccountingPeriodItem T where (T.month between :month and :stopMonth) and T.accountingPeriod.company.id=:company and T.accountingPeriod.year=:year")
    List<AccountingPeriodItem> findByCompanyAndMonthAndStopMonthAndYear(@Param("company") String company, @Param("month") int month, @Param("stopMonth")int stopMonth , @Param("year") int year);

    @Query("select T from AccountingPeriodItem T where T.yearMonth > :yearMonth and T.accountingPeriod.company.id=:company and (T.carryOverPLFlag = true OR T.monthlyFlag = true)")
    List<AccountingPeriodItem> findByCompanyAndYearMonth(@Param("company") String company, @Param("yearMonth") int yearMonth);


}
